$(function() {	
	
	subsystemID = 0;
	componentID = 0;
	subcomponentID = 0;
	deviceID = 0;
	
	menuSubsystem = $('#main_menu_div');
	var accordion_head = $('.maccordion > li > a'),
		accordion_body = $('.maccordion li > .msub-menu');

	menuSubsystem.find('#tools').addClass('active').next().slideDown("slow");

	accordion_head.on('click', function(event) {				
		// Show and hide the tabs on click	
		if ($(this).attr('class') != 'active'){
			accordion_body.slideUp("normal");
			$(this).next().stop(true,true).slideToggle("normal");
			accordion_head.removeClass('active');
			$(this).addClass('active');
		}
	}); 
	
	var fromTime = new Date();
	var toTime   = new Date();	
	var fromDate = new Date();
	var toDate   = new Date();
	fromDate.setDate(fromDate.getDate() -7);
	toDate.setDate(toDate.getDate() +1);
	fromDate = $.datepicker.formatDate('yy/mm/dd', fromDate);
	toDate = $.datepicker.formatDate('yy/mm/dd', toDate);
	fromTime = [fromTime.getHours(), fromTime.getMinutes(), fromTime.getSeconds()].join(':');
	toTime = [toTime.getHours(), toTime.getMinutes(), toTime.getSeconds()].join(':');		
	$('#stationlog_search #fromDate').attr('value', fromDate);
	$('#stationlog_search #toDate').attr('value', toDate);
	$('#stationlog_search #fromTime').attr('value', fromTime);
	$('#stationlog_search #toTime').attr('value', toTime);	
	
	// Process Form Data
	$('#stationlog_search_button').on( 'click',function() {
		stationLogTitle = 'Station Log Details - General';
		$('#stationlog_search').find('.bBlue').removeClass('bBlue');	    
		fetchStationLogs();
	});
	$('#stationlog_search_clear' ).on( 'click',function() { 
		$(this).closest('form').find("input[type=text], textarea").val("");
 	});
 	
	// Statistical Data
	$('#btn_stationlog_my').on('click', function() {
		stationLogTitle = 'Station Log Details - My Station Logs';
		$('#stationlog_search').find('.bBlue').removeClass('bBlue');	    
		$('#btn_stationlog_my a').toggleClass('bBlue');
		fetchMyStationLogs();
	});
	
	$('#btn_stationlog_7d').on('click', function() {	
		stationLogTitle = 'Station Log Details - Last 7 Days';	
		var fromDate = new Date();
		fromDate.setDate(fromDate.getDate() -7);
		var fromDate = $.datepicker.formatDate('yy/mm/dd', fromDate);
		var toDate = $.datepicker.formatDate('yy/mm/dd', new Date());
		$('#stationlog_search #fromDate').attr('value', fromDate);
		$('#stationlog_search #toDate').attr('value', toDate);
		$('#stationlog_details_title').attr('label', 'Station Log Details - Last 7 Days');
		$('#stationlog_search').find('.bBlue').removeClass('bBlue');	    
		$('#btn_stationlog_7d a').toggleClass('bBlue');
		fetchStationLogs();
	});
	$('#btn_stationlog_30d').on('click', function() {	
		stationLogTitle = 'Station Log Details - Last 30 Days';	
		var fromDate = new Date();
		fromDate.setDate(fromDate.getDate() -30);
		var fromDate = $.datepicker.formatDate('yy/mm/dd', fromDate);
		var toDate = $.datepicker.formatDate('yy/mm/dd', new Date());
		$('#stationlog_search #fromDate').attr('value', fromDate);
		$('#stationlog_search #toDate').attr('value', toDate);
		$('#stationlog_search').find('.bBlue').removeClass('bBlue');	    
		$('#btn_stationlog_30d a').toggleClass('bBlue');		
		fetchStationLogs();
	});	
	$('#btn_stationlog_24h').on('click', function() {	
		stationLogTitle = 'Station Log Details - Last 24 Hours';	
		var fromTime = new Date();
		var toTime   = new Date();
		fromTime.setHours(fromTime.getHours() -24);			
		var fromDate = $.datepicker.formatDate('yy/mm/dd', fromTime);
		var toDate = $.datepicker.formatDate('yy/mm/dd', toTime);
		
		fromTime = [fromTime.getHours(), fromTime.getMinutes(), fromTime.getSeconds()].join(':');
		toTime = [toTime.getHours(), toTime.getMinutes(), toTime.getSeconds()].join(':');
		
		$('#stationlog_search #fromDate').attr('value', fromDate);
		$('#stationlog_search #toDate').attr('value', toDate);
		$('#stationlog_search #fromTime').attr('value', fromTime);
		$('#stationlog_search #toTime').attr('value', toTime);	
		$('#stationlog_search').find('.bBlue').removeClass('bBlue');	    
		$('#stationlog_24h a').toggleClass('bBlue');			
	    fetchStationLogs();
	});		

 	$('#stationlog_search #stationlog_add').click(function () {
        $('#stationlog_dialog').dialog('open');
        $('#stationlog_success').hide();
        $('#stationlog_failure').hide();
        $('#stationlog_dialog #subsystem_nm').attr('value', '');
        $('#stationlog_dialog #component_nm').attr('value', '');
        $('#stationlog_dialog #subcomponent_nm').attr('value', '');	
        $('#stationlog_dialog #device_host').attr('value', ''); 
        $('#stationlog_dialog #insert_dt').datepicker({dateFormat:"yy-mm-dd"}).datepicker("setDate",new Date());  	        	           
       	$("#log_entry").cleditor({
			width:"auto", 
			height:"250px",
			bodyStyle: "margin: 10px; font: 12px Arial,Verdana; cursor:text; background-color: white;",
			useCSS:true
		}); 
    	$('#stationlog_dialog #insert_ts').timeEntry({
			show24Hours: true, // 24 hours format
			showSeconds: true, // Show seconds?
			defaultTime: new Date(),
			spinnerImage: '../../assets/images/elements/ui/spinner.png', // Arrows image
			spinnerSize: [19, 26, 0], // Image size
			spinnerIncDecOnly: true // Only up and down arrows
		});	
		$('.ui-timepicker').css('float','left');
		var createTime = new Date();
		createTime = [createTime.getHours(), createTime.getMinutes(), createTime.getSeconds()].join(':');
		$('#stationlog_dialog #insert_ts').attr('value', createTime);
	});  
		
	function fetchStationLogs(){
		var form = $('#stationlog_search');
		
		$.ajax({
			url: 		'stationlog/get_station_logs',
			type: 		'POST', 
			data:		form.serialize(),
			dataType: 	'json',
			success: 	processStationLogs
		})	
	}
	
	function fetchMyStationLogs(){
		var form = $('#stationlog_search');
		
		$.ajax({
			url: 		'stationlog/get_my_station_logs',
			type: 		'POST', 
			data:		form.serialize(),
			dataType: 	'json',
			success: 	processStationLogs
		})	
	}

	function processStationLogs(results){
        if (results.message == 'ok'){
        	$('#stationlog_main').html(results.html);   
			$("#stationlog_main select").uniform();  
			$('#stationlog_details_title').text(stationLogTitle); 

	        $("#stationlog_tbl tbody").on('click', 'tr', (function(event) {  
	        	
	        	$('#stationlog_tbl').find('.thisRow').removeClass('thisRow');	        	
				$(this).addClass('thisRow');
				
				stationlogID = $(this).find('#stationlog_main_id_td').text();
				subsystemName  = $(this).find('#subsystem_nm_td').text();
				componentName  = $(this).find('#component_nm_td').text();
				subcomponentName  = $(this).find('#subcomponent_nm_td').text();
				hostName  = $(this).find('#host_nm_td').text();
				userID 	= $(this).find('#user_id_td').text(); 
        		mttsTicket = $(this).find('#mtts_ticket_td').text(); 
        		pstnTicket = $(this).find('#pstn_ticket_td').text(); 
        		heatTicket = $(this).find('#heat_ticket_td').text(); 
        		insertDt = $(this).find('#insert_date_td').text();
        		firstLogEntry  = $(this).find('#log_entry_td').html();
        		      	
			}));  
										
        }
        else{
            this.buildMsg('nNote nWarning','There was an error processing your request. Please try again.');
        }
        
		//===== Dialog Link based on Selection ===== //
	    $('#stationlog_dropdown li #stationlog_add').click(function () {
	        $('#stationlog_dialog').dialog('open');
	        $('#stationlog_success').hide();
	        $('#stationlog_failure').hide();
	        $('#stationlog_dialog #subsystem_nm').attr('value', '');
	        $('#stationlog_dialog #component_nm').attr('value', '');
	        $('#stationlog_dialog #subcomponent_nm').attr('value', '');	
	        $('#stationlog_dialog #device_host').attr('value', ''); 
	        $('#stationlog_dialog #activity_dt').datepicker({dateFormat:"yy-mm-dd"}).datepicker("setDate",new Date());          
	       	$("#log_entry").cleditor({
				width:"auto", 
				height:"250px",
				bodyStyle: "margin: 10px; font: 12px Arial,Verdana; cursor:text; background-color: white;",
				useCSS:true
			});
        	$('#stationlog_dialog #activity_ts').timeEntry({
				show24Hours: true, // 24 hours format
				showSeconds: true, // Show seconds?
				defaultTime: new Date(),
				spinnerImage: '../../assets/images/elements/ui/spinner.png', // Arrows image
				spinnerSize: [19, 26, 0], // Image size
				spinnerIncDecOnly: true // Only up and down arrows
			});	
			$('.ui-timepicker').css('float','left');			
			var createTime = new Date();
			createTime = [createTime.getHours(), createTime.getMinutes(), createTime.getSeconds()].join(':');
			$('#stationlog_dialog #activity_ts').attr('value', createTime);
				

	    });
	    
	    $('#stationlog_widget #stationlog_widget_add').click(function () {
	        $('#stationlog_dialog').dialog('open');
	        $('#stationlog_success').hide();
	        $('#stationlog_failure').hide();
	        $('#stationlog_dialog #subsystem_nm').attr('value', '');
	        $('#stationlog_dialog #component_nm').attr('value', '');
	        $('#stationlog_dialog #subcomponent_nm').attr('value', '');	
	        $('#stationlog_dialog #device_host').attr('value', ''); 
	        $('#stationlog_dialog #activity_dt').datepicker({dateFormat:"yy-mm-dd"}).datepicker("setDate",new Date());  	        	           
	       	$("#log_entry").cleditor({
				width:"auto", 
				height:"250px",
				bodyStyle: "margin: 10px; font: 12px Arial,Verdana; cursor:text; background-color: white;",
				useCSS:true
			}); 
        	$('#stationlog_dialog #activity_ts').timeEntry({
				show24Hours: true, // 24 hours format
				showSeconds: true, // Show seconds?
				defaultTime: new Date(),
				spinnerImage: '../../assets/images/elements/ui/spinner.png', // Arrows image
				spinnerSize: [19, 26, 0], // Image size
				spinnerIncDecOnly: true // Only up and down arrows
			});	
			$('.ui-timepicker').css('float','left');
			var createTime = new Date();
			createTime = [createTime.getHours(), createTime.getMinutes(), createTime.getSeconds()].join(':');
			$('#stationlog_dialog #activity_ts').attr('value', createTime);
	    });        

	    $('#stationlog_dropdown li #stationlog_edit').click(function () {
	        $('#stationlog_dialog_edit').dialog('open');		        
	        $('#stationlog_edit_success').hide();
	        $('#stationlog_edit_failure').hide();
	        $('#stationlog_dialog_edit #user_id').attr('value', userID);  
	        $('#stationlog_dialog_edit #mtts_ticket').attr('value', mttsTicket);  	
	        $('#stationlog_dialog_edit #pstn_ticket').attr('value', pstnTicket); 
	        $('#stationlog_dialog_edit #heat_ticket').attr('value', heatTicket);
	        $('#stationlog_dialog_edit #insert_dt').datepicker({dateFormat:"yy-mm-dd"}).datepicker("setDate",new Date(insertDt));  
	        $("#stationlog_dialog_edit #first_log_entry").cleditor({
				width:"auto", 
				height:"250px",
				bodyStyle: "margin: 10px; font: 12px Arial,Verdana; cursor:text; background-color: white;",
				useCSS:true
			});	
	        $('#stationlog_dialog_edit #first_log_entry').val(firstLogEntry).blur(); 
       	        
	        $("#stationlog_edit_form #log_entry_edit").cleditor({
				width:"auto", 
				height:"250px",
				bodyStyle: "margin: 10px; font: 12px Arial,Verdana; cursor:text; background-color: white;",
				useCSS:true
			});
			$('#stationlog_dialog_edit #log_entry_edit').val('').blur(); 
        	$('#stationlog_dialog_edit #insert_ts').timeEntry({
				show24Hours: true, // 24 hours format
				showSeconds: true, // Show seconds?
				defaultTime: new Date(),
				spinnerImage: '../../assets/images/elements/ui/spinner.png', // Arrows image
				spinnerSize: [19, 26, 0], // Image size
				spinnerIncDecOnly: true // Only up and down arrows
			});	
			$('.ui-timepicker').css('float','left');
			var createTime = new Date();
			createTime = [createTime.getHours(), createTime.getMinutes(), createTime.getSeconds()].join(':');
			$('#stationlog_dialog_edit #insert_ts').attr('value', createTime);	
			$('#stationlog_dialog_edit #activity_dt').datepicker({dateFormat:"yy-mm-dd"}).datepicker("setDate",new Date(insertDt));  
	    	$('#stationlog_dialog_edit #activity_ts').timeEntry({
				show24Hours: true, // 24 hours format
				showSeconds: true, // Show seconds?
				defaultTime: new Date(),
				spinnerImage: '../../assets/images/elements/ui/spinner.png', // Arrows image
				spinnerSize: [19, 26, 0], // Image size
				spinnerIncDecOnly: true // Only up and down arrows
			});			
	    });
        
		// Dialog
	    $('#stationlog_dialog').dialog({
	        autoOpen: false,
	        width: 600,
	        modal: true,
	       	open: function(event, ui) {
	        	
	        	s1 = $('#subsystem_dropdown_div').empty();
	        	s2 = $('#component_dropdown_div');
	        	s3 = $('#subcomponent_dropdown_div');
	        	s4 = $('#device_dropdown_div');
	        	s1[0].enabled = false;
	        	s2[0].enabled = false;
	        	s3[0].enabled = false;
	        	s4[0].enabled = false;
	        	
				$.ajax({
					url: 		'../subsystem/subsystem/get_subsystem_dropdown',
					type: 		'POST', 
					dataType: 	'json',
					success: 	function (results) {
									s1.html(results.html);
									$("#subsystem_dropdown_div select").uniform(); 
			                        s1[0].enabled = true;
			                    }
				});	
				
				subsystemID = $(this).find(':selected').attr('id');
				
				$.ajax({
				url: 		'../subsystem/subsystem/get_component_dropdown',
				type: 		'POST', 
				dataType: 	'json',
				data:		{'subsystem_id': subsystemID},
				success: 	function (results) {
		                        s2.empty().html(results.html);
		                        $("#component_dropdown_div select").uniform(); 
		                        s2[0].enabled = true;
		                    }
				});	
				
				s1.on('change', function(){
					subsystemID = $(this).find(':selected').attr('id');
					fetchComponents( subsystemID );
					$("#subcomponent_dropdown_div #subcomponent_nm_i option:contains(" + 'NA' + ")").attr('selected', 'selected'); 	
					$('#subcomponent_dropdown_div #uniform-subcomponent_nm_i span').text('NA');
					$("#device_dropdown_div #device_nm_i option:contains(" + 'NA' + ")").attr('selected', 'selected'); 	
					$('#device_dropdown_div #uniform-device_nm_i span').text('NA');
				})
				

				componentID = $(this).find(':selected').attr('id');
				
				$.ajax({
				url: 		'../subsystem/subsystem/get_subcomponent_dropdown',
				type: 		'POST', 
				dataType: 	'json',
				data:		{'component_id': componentID},
				success: 	function (results) {
		                        s3.empty().html(results.html);
		                        $("#subcomponent_dropdown_div select").uniform(); 
		                        s3[0].enabled = true;
		                    }
				});		

				s2.on('change', function(){
					componentID = $(this).find(':selected').attr('id');
					fetchSubcomponents( componentID );
					s4.val( s4.prop('defaultSelected') );
				})

				
				subcomponentID = $(this).find(':selected').attr('id');
				
				$.ajax({
				url: 		'../subsystem/subsystem/get_device_dropdown',
				type: 		'POST', 
				dataType: 	'json',
				data:		{'subcomponent_id': subcomponentID},
				success: 	function (results) {
		                        s4.empty().html(results.html);
		                        $("#device_dropdown_div select").uniform(); 
		                        s4[0].enabled = true;
		                    }
				});	
				
				s3.on('change', function(){
					subcomponentID = $(this).find(':selected').attr('id');
					fetchDevices( subcomponentID );
				})							
				
				
	        },				
	        buttons: {
	            "Save": function () {
	            			var form = $('#stationlog_add_form');
	            			console.log('form ... ' + form.serialize());
							
							$.ajax({
								url: 		'stationlog/add_stationlog',
								type: 		'POST', 
								data:		form.serialize(),
								dataType: 	'json',
								success: 	addStationlogResults
							})	
	            },
	            "Cancel": function () {
	            	$(this).closest('form').find("input[type=text], textarea").val("");
	                $(this).dialog("close");
	            }
	        }
	    });
	    
		function fetchComponents(subsystemID) {
			
			//subsystemID = $(this).find(':selected').attr('id');
	       	s2[0].enabled = false;			
			
			$.ajax({
			url: 		'../subsystem/subsystem/get_component_dropdown',
			type: 		'POST', 
			dataType: 	'json',
			data:		{'subsystem_id': subsystemID},
			success: 	function (results) {
	                        s2.empty().html(results.html);
	                        $("#component_dropdown_div select").uniform(); 
	                        $("#component_dropdown_edit_div select").uniform(); 
	                        s2[0].enabled = true;
	                    }
			});			       	
								
		}	    		

		function fetchSubcomponents( componentID ) {
			
			//componentID = $(this).find(':selected').attr('id');
			
	       	s3[0].enabled = false;			
			
				$.ajax({
				url: 		'../subsystem/subsystem/get_subcomponent_dropdown',
				type: 		'POST', 
				dataType: 	'json',
				data:		{'component_id': componentID},
				success: 	function (results) {
		                        s3.empty().html(results.html);
		                        $("#subcomponent_dropdown_div select").uniform(); 
		                        $("#subcomponent_dropdown_edit_div select").uniform();
		                        s3[0].enabled = true;
		                    }
				});					
		}

		function fetchDevices( subcomponentID ) {
			
			//subcomponentID = $(this).find(':selected').attr('id');
			
	       	s4[0].enabled = false;			
			
			$.ajax({
			url: 		'../subsystem/subsystem/get_device_dropdown',
			type: 		'POST', 
			dataType: 	'json',
			data:		{'subcomponent_id': subcomponentID},
			success: 	function (results) {
	                        s4.empty().html(results.html);
	                        $("#device_dropdown_div select").uniform(); 
	                        $("#device_dropdown_edit_div select").uniform(); 
	                        s4[0].enabled = true;
	                    }
			});					
		}

		function addStationlogResults(results){
			$('#stationlog_success').hide();
			$('#stationlog_failure').hide();		
			
	        if (results.ret == 'ok' ){	
	        	$('#stationlog_add_form').find("input[type=text], textarea").val("");
	        	$('#stationlog_add_form').find("#log_entry").val("");
	        	$('#stationlog_success').show();	
	        }
	        else{
	        	$('#stationlog_failure').show();
	        }	
	
	    	$(".nNote").click(function() {
				$(this).fadeTo(200, 0.00, function(){ //fade
					$(this).slideUp(200, function() { //slide up
						$(this).remove(); //then remove from the DOM
					});
				});
			});	

			$('#stationlog_search').find('.green').removeClass('green');	    
			$('#stationlog_my a').toggleClass('green');
			fetchMyStationLogs();	
					
		}        

	    $('#stationlog_dialog_edit').dialog({
	        autoOpen: false,
	        width: 650,
	        modal: true,
	       	open: function(event, ui) {
	        	
	        	s1 = $('#subsystem_dropdown_edit_div').empty();
	        	s2 = $('#component_dropdown_edit_div');
	        	s3 = $('#subcomponent_dropdown_edit_div');
	        	s4 = $('#device_dropdown_edit_div');
	        	s1[0].enabled = false;
	        	s2[0].enabled = false;
	        	s3[0].enabled = false;
	        	s4[0].enabled = false;
	        	
				$.ajax({
					url: 		'../subsystem/subsystem/get_subsystem_dropdown',
					type: 		'POST', 
					dataType: 	'json',
					success: 	function (results) {
									s1.html(results.html);
									$("#subsystem_dropdown_edit_div select").uniform(); 
									$('#subsystem_dropdown_edit_div #uniform-subsystem_nm_i span').text(subsystemName); 
									$("#subsystem_dropdown_edit_div #subsystem_nm_i option:contains(" + subsystemName + ")").attr('selected', 'selected');
									
			                        s1[0].enabled = true;

			                        subsystemID = s1.find(':selected').attr('id');	 								
									
									$.ajax({
									url: 		'../subsystem/subsystem/get_component_dropdown',
									type: 		'POST', 
									dataType: 	'json',
									data:		{'subsystem_id': subsystemID},
									success: 	function (results) {
							                        s2.empty().html(results.html);
													$("#component_dropdown_edit_div select").uniform(); 
													$('#component_dropdown_edit_div #uniform-component_nm_i span').text(componentName); 
													$("#component_dropdown_edit_div #component_nm_i option:contains(" + componentName + ")").attr('selected', 'selected'); 	
																								
							                        s2[0].enabled = true;
							                        
													componentID = s2.find(':selected').attr('id');
													
													$.ajax({
													url: 		'../subsystem/subsystem/get_subcomponent_dropdown',
													type: 		'POST', 
													dataType: 	'json',
													data:		{'component_id': componentID},
													success: 	function (results) {
											                        s3.empty().html(results.html);
											                        $("#subcomponent_dropdown_edit_div select").uniform(); 
																	$("#subcomponent_dropdown_edit_div #subcomponent_nm_i option:contains(" + subcomponentName + ")").attr('selected', 'selected'); 	
																	$('#subcomponent_dropdown_edit_div #uniform-subcomponent_nm_i span').text(subcomponentName);							                        
											                        s3[0].enabled = true;
											                        
											                        subcomponentID = s3.find(':selected').attr('id');
				
																	$.ajax({
																	url: 		'../subsystem/subsystem/get_device_dropdown',
																	type: 		'POST', 
																	dataType: 	'json',
																	data:		{'subcomponent_id': subcomponentID},
																	success: 	function (results) {
															                        s4.empty().html(results.html);
															                        $("#device_dropdown_edit_div select").uniform(); 
															                        $("#device_dropdown_edit_div #device_nm_i option:contains(" + hostName + ")").attr('selected', 'selected'); 	
																					$('#device_dropdown_edit_div #uniform-device_nm_i span').text(hostName);
															                        s4[0].enabled = true;
															                    }
																	});																									                        											                        
											                    }
													});								                        							                        
							                    }
									});								
			                    }
				});	
	
				
				s1.on('change', function(){
					subsystemID = $(this).find(':selected').attr('id');
					fetchComponents( subsystemID );
					$("#subcomponent_dropdown_edit_div #subcomponent_nm_i option:contains(" + 'NA' + ")").attr('selected', 'selected'); 	
					$('#subcomponent_dropdown_edit_div #uniform-subcomponent_nm_i span').text('NA');
					$("#device_dropdown_div #device_nm_i option:contains(" + 'NA' + ")").attr('selected', 'selected'); 	
					$('#device_dropdown_div #uniform-device_nm_i span').text('NA');
				});
				
				s2.on('change', function(){
					componentID = $(this).find(':selected').attr('id');
					fetchSubcomponents( componentID );
					s4.val( s4.prop('defaultSelected') );
					$("#device_dropdown_div #device_nm_i option:contains(" + 'NA' + ")").attr('selected', 'selected'); 	
					$('#device_dropdown_div #uniform-device_nm_i span').text('NA');
				});
				
				s3.on('change', function(){
					subcomponentID = $(this).find(':selected').attr('id');
					fetchDevices( subcomponentID );
				});	
				
				},       
	        buttons: {
	            "Update": function () {
	            			var form = $('#stationlog_edit_form');
	            			$('#stationlog_edit_form #stationlog_main_id').attr('value', stationlogID);
	            			console.log (form.serialize());
							
							$.ajax({
								url: 		'stationlog/add_stationlog_update',
								type: 		'POST', 
								data:		 form.serialize(),
								dataType: 	'json',
								success: 	editStationlogResults
								})	
	            },
	            "Cancel": function () {
	            	$(this).closest('form').find("input[type=text], textarea").val("");
	                $(this).dialog("close");
	            }
	        }
	    });	
	    
	    
		function editStationlogResults(results){
			$('#stationlog_edit_success').hide();
			$('#stationlog_edit_failure').hide();
	        if (results.ret == 'ok' ){	
	        	$('#stationlog_edit_form').find("input[type=text], textarea").val("");
	        	$('#stationlog_edit_form').find("#log_entry").val("");
	        	$('#stationlog_edit_success').show();	
	        }
	        else{
	        	$('#stationlog_edit_failure').show();
	        }	
	
	    	$(".nNote").click(function() {
				$(this).fadeTo(200, 0.00, function(){ //fade
					$(this).slideUp(200, function() { //slide up
						$(this).remove(); //then remove from the DOM
					});
				});
			});	
			
		}
        
        
	};			

	$( ".datepicker" ).datepicker({ 
		defaultDate: +7,
		showOtherMonths:true,
		autoSize: true,
		appendText: '(dd-mm-yyyy)',
		dateFormat: 'dd-mm-yy'
	});	
	
	$(function() {
			var dates = $( "#fromDate, #toDate" ).datepicker({
				defaultDate: "+1w",
				changeMonth: false,
				showOtherMonths:true,
				numberOfMonths: 3,
				onSelect: function( selectedDate ) {
					var option = this.id == "fromDate" ? "minDate" : "maxDate",
						instance = $( this ).data( "datepicker" ),
						date = $.datepicker.parseDate(
							instance.settings.dateFormat ||
							$.datepicker._defaults.dateFormat,
							selectedDate, instance.settings );
					dates.not( this ).datepicker( "option", option, date );
				}
			});
		});
		
	//===== Time picker =====//
	
	$('.timepicker').timeEntry({
		show24Hours: true, // 24 hours format
		showSeconds: true, // Show seconds?
		spinnerImage: '../../assets/images/elements/ui/spinner.png', // Arrows image
		spinnerSize: [19, 26, 0], // Image size
		spinnerIncDecOnly: true // Only up and down arrows
	});	


	
});	
